﻿using System;
using Xoohoo.Extensions;
using System.Collections.Generic;

namespace Xoohoo.Models.ViewModels
{
    public class PromptViewModel
    {
        private string _returnText;
        private string _returnUrl;

        public string Title { get; set; }

        public List<string> Message { get; set; }

        public string ReturnText
        {
            get { if (_returnText.IsNullOrWhiteSpace()) _returnText = "返回上一页"; return _returnText; }
            set { _returnText = value; }
        }

        public string ReturnUrl
        {
            get { if (_returnUrl.IsNullOrWhiteSpace()) _returnUrl = "javascript:history.back();"; return _returnUrl; }
            set { _returnUrl = value; }
        }

        public PromptViewModel(string title)
            : this(title, null)
        {
            Title = title;
        }

        public PromptViewModel(string title, IEnumerable<String> message)
        {
            Title = title;
            Message = message == null ? new List<String>() : new List<String>(message);
        }

        public PromptViewModel(string title, IEnumerable<String> message, string returnText, string returnUrl)
            : this(title, message)
        {
            ReturnText = returnText;
            ReturnUrl = returnUrl;
        }
 
        public void AddMessage(string message)
        {
            if(!message.IsNullOrWhiteSpace())
                Message.Add(message);
        }

        public void AddMessages(IEnumerable<String> message)
        {
            if (message == null)
                throw new ArgumentNullException("message");

            Message.AddRange(message);
        }
    }
}
